package com.bkaka.controller;

import com.bkaka.bean.ResponseBean;
import com.bkaka.entity.ExamCategory;
import com.bkaka.service.ExamCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by maxiaoqiang on 2018/9/3.
 */
@RestController
@RequestMapping(value = "${api.path}/category")
public class ExamCategoryController {

    @Autowired
    private ExamCategoryService service;

    @GetMapping(value = "/list")
    public ResponseBean findAll(){
        List<ExamCategory> list = service.findAll();
        return new ResponseBean(200, "SUCCESS", list);
    }

    @GetMapping(value = "/categoryandsubject")
    public ResponseBean findCategorySubject(){
        List<ExamCategory> list = service.findCategorySubject();
        return new ResponseBean(200, "SUCCESS", list);
    }

    @ResponseBody
    @PostMapping(value = "/create", produces = "application/json;charset=UTF-8")
    public ResponseBean create(@Valid @RequestBody ExamCategory category) {
        service.create(category);
        return new ResponseBean(200, "SUCCESS", category);
    }

    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json;charset=UTF-8")
    public ResponseBean update(@Valid @RequestBody ExamCategory category) {
        service.update(category);
        return new ResponseBean(200, "SUCCESS", category);
    }

    @ResponseBody
    @PostMapping(value = "/delete", produces = "application/json;charset=UTF-8")
    public ResponseBean delete(Integer id) {
        service.delete(id);
        return new ResponseBean(200, "SUCCESS", "");
    }

}
